1363C - Game On Leaves - CodeForces Solution


games trees *1600

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    n, x = map(int, input().split())
    count = 0

    for i in range(n-1):
        u, v = map(int, input().split())
        if u == x or v == x:
            count +=1
            
    if n == 1 and x == 1:
        print("Ayush")

    elif count == 1:
        print("Ayush")

    elif n%2 == 0:
        print("Ayush")

    elif n%2 == 1:
        print("Ashish")

C++ Code:

#include <bits/stdc++.h>
using namespace std;
 
#define int               int64_t
#define rep(i,a,b)        for(int i = a; i < b; i++)
#define rrep(i,a,b)       for(int i = b; i >=a; i--)
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define emb               emplace_back
#define mp                make_pair
#define all(x)            (x).begin(),(x).end()
#define sz(x)             (int)(x.size())
#define fr                first
#define sc                second
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define pii               pair<int,int>
#define vi                vector<int>
#define v2i               vector<vi>
#define vp                vector<pii>
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
#define cpar              __builtin_parity
#define sum(a,x)          accumulate(all(a),x)
#define lowb(a,x)         lower_bound(all(a),x) - a.begin()
#define uppb(a,x)         upper_bound(all(a),x) - a.begin()
#define maxpq             priority_queue<int>
#define minpq             priority_queue<int,vector<int>,greater<int>>
#define endl              "\n"
const int MOD = 1e9 + 7;
 
template<typename T,typename V> inline T amax(T &a,V b){if(b>a)a=b;return a;}
template<typename T,typename V> inline T amin(T &a,V b){if(b<a)a=b;return a;}
template <typename T> inline T gcd(T a, T b) {while (b != 0) swap(b, a %= b); return a;}
template <typename T> inline T inv(T i) {if (i == 1) return 1; return (MOD - ((MOD / i) * inv(MOD % i)) % MOD) % MOD;}
/*--------------------------------------------------------------------------*/
//Debug Area
 
#ifndef Ana
#define debug(x) cerr << #x <<" "; print(x); cerr << endl;
#else
#define debug(x);
#endif
 
template <typename T> void print(T t) {cerr << t;}
 
template <typename T, typename V> void print(pair <T, V> p);
template <typename T> void print(vector <T> v);
template <typename T> void print(set <T> v);
template <typename T, typename V> void print(map <T, V> v);
template <typename T> void print(multiset <T> v);
 
template <typename T, typename V> void print(pair <T, V> p) {cerr << "{"; print(p.fr); cerr << ","; print(p.sc); cerr << "}";}
template <typename T> void print(vector <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <typename T> void print(set <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <typename T, typename V> void print(map <T, V> v) {cerr << "[ "; for (auto i : v) {print(i); cerr << " ";} cerr << "]";}
template <typename T> void print(multiset <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
 
/*--------------------------------------------------------------------------*/
 
const int INF = 1e18;
const int32_t M = 998244353;
 
 
const int N = 1e5 + 10;

const int mod =  998244353;
 
int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

void solve(int test_cases)
{ 
     // cout<<"Case #"<<test_cases<<":"<<" ";
    int n,x;
    cin>>n>>x;
    --x;
    v2i adj(n);
    rep(i,0,n-1)
    {
        int u,v;
        cin>>u>>v;
        --u,--v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    if(sz(adj[x])<=1 || (n-1)&1 == 1)
    {
        cout<<"Ayush"<<endl;
    }
    else cout<<"Ashish"<<endl;
    return;
}

signed main()
{
   
   ios::sync_with_stdio(false);
   cin.tie(NULL);
 
   #ifdef SIEVE
    sieve();
   #endif
 
   #ifdef Ana
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
   #endif
   #ifndef Ana
     freopen("error.txt", "w", stderr);
   #endif
   
   int t = 1;
   cin>>t;
   int T = 1;
 
   while(t--)
   {
     solve(T);
     T++;
   }
 
   cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
 
   return 0;
}


Comments

Submit
0 Comments
More Questions

1302. Deepest Leaves Sum
1209. Remove All Adjacent Duplicates in String II
994. Rotting Oranges
983. Minimum Cost For Tickets
973. K Closest Points to Origin
969. Pancake Sorting
967. Numbers With Same Consecutive Differences
957. Prison Cells After N Days
946. Validate Stack Sequences
921. Minimum Add to Make Parentheses Valid
881. Boats to Save People
497. Random Point in Non-overlapping Rectangles
528. Random Pick with Weight
470. Implement Rand10() Using Rand7()
866. Prime Palindrome
1516A - Tit for Tat
622. Design Circular Queue
814. Binary Tree Pruning
791. Custom Sort String
787. Cheapest Flights Within K Stops
779. K-th Symbol in Grammar
701. Insert into a Binary Search Tree
429. N-ary Tree Level Order Traversal
739. Daily Temperatures
647. Palindromic Substrings
583. Delete Operation for Two Strings
518. Coin Change 2
516. Longest Palindromic Subsequence
468. Validate IP Address
450. Delete Node in a BST